home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: Floating Point: Overflow ?
- Date: 9 Feb 1996 19:04:09 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4fg5r9$bqm@dawn.mmm.com>
- References: <311927bc.318595@198.112.179.16>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- confused (confused@c++.oop) wrote:
- > I am confused and a bit embarassed by this problem! I really should
- > know the answer but ...
-
- > I am using BC++ 4.52 and am doing a review of C++ using the text
- > "Object-Oriented Programming in C++" by Robert Lafore. One exercise is
- > giving me a floating point overflow error. Basically the user input is
- > a number of gallons of water and the output is the number of cubic
- > feet the water occupies.
-
- > #include<iostream.h>
-
- > void main()
- > {
- > float gals;
- > cin << gals;
- > cout >> endl >> gals/7.481;
- > }
-
- When I try to compile this, I get:
- "x.cc", line 4: Warning (Anachronism): main() must have a return type of int.
- "x.cc", line 4: Note: Type "CC -migration" for more on anachronisms.
- "x.cc", line 6: Error: The operation "istream_withassign << float" is illegal.
- "x.cc", line 7: Error: Trying to take the address of the overloaded function endl.
- "x.cc", line 7: Error: The operation "ostream_withassign >> int" is illegal.
-
- I'm surprised that your compiler did not complain. The following program works
- much better. Notice that the direction of the "arrows" on cin and cout are
- reversed.
-
- #include <iostream.h>
-
- int main()
- {
- float gals;
- cin >> gals;
- cout << gals/7.481 << endl;
- return 0;
- }
-
- > When the input is an integer value (ie 5) there is no problem but when
- > the input is a decimal value (ie 5.5) I receive the overflow error.
- > Why am a receiving the error and how do I avoid this in the future?
-
- When I enter 5.5 the program prints out 0.735196.
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-